package org.jh

import org.multiverse.annotations.TransactionalMethod
import org.multiverse.annotations.TransactionalObject

@TransactionalObject
class Account {
	private int balance
	private name
	
	Account(name, int balance) {
		this.name = name
		this.balance = balance
	}
	
	@TransactionalMethod(readonly = true)
	def getBalance() {
		return balance
	}
	
	void setBalance(int newBalance) {
		if(newBalance<0){
			throw new IllegalArgumentException("An account can't have a negative balance");
		}
		this.balance = newBalance
	}
	
	@TransactionalMethod(readonly = true)
	public String toString() {
		"Account-${name}(balance=${balance})"
	}

}
